package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 *调用Person
 */
public class Test4 {
    public static void main(String[] args) throws  Exception {
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class);
        Object obj = c.newInstance("张三");
        Method[] methods = cls.getDeclaredMethods();
        for (Method method : methods){
            boolean mark = method.isAnnotationPresent(AutoRunMethod.class);
            if (mark){
                AutoRunMethod arm = method.getAnnotation(AutoRunMethod.class);
                int value = arm.value();
                System.out.println("调用方法:"+method.getName()+"()"+value+"次");
                for (int i=0;i<value;i++){
                    method.invoke(obj);
                }
            }else {
                System.out.println(method.getName()+"()没有被标注");
            }
        }
    }
}
